package org.jeecg.modules.business.outbound.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.outbound.entity.WmsOutReceiptTaskPick;
import org.jeecg.modules.business.outbound.entity.vo.*;
import org.jeecg.modules.business.outbound.service.IWmsOutReceiptTaskPickService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 出库任务-拣货
 *
 * @author gongwenkai
 * @version 1.0.0
 * @since 2023-10-10
 */
@RequiredArgsConstructor
@Api(tags = "出库任务-拣货")
@RestController
@RequestMapping("/business/wmsOutReceiptTask/pick")
@Slf4j
public class WmsOutReceiptTaskPickController {

    private final IWmsOutReceiptTaskPickService wmsOutReceiptTaskPickService;


    /**
     * 查询所有未拣货信息
     * @param taskId
     * @param materialName
     * @param batchCode
     * @return
     */
    @ApiOperation(value = "查询所有未拣货信息", notes = "查询所有未拣货信息")
    @GetMapping(value = "/listAllUnPick")
    public Result<IPage<OutboundTaskUnPickVO>> listAllUnPick(@RequestParam(value = "taskId") String taskId,
                                                             @RequestParam(value = "materialName",required = false) String materialName,
                                                             @RequestParam(value = "batchCode",required = false) String batchCode,
                                                             @RequestParam(value = "deviceType",required = false) String deviceType,
                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
                                                              ){
        IPage<WmsOutReceiptTaskPick> page = new Page<>(pageNo, pageSize);
        IPage<OutboundTaskUnPickVO> pageList=wmsOutReceiptTaskPickService.listAllUnPick(page,taskId,materialName,batchCode,deviceType);
        return Result.ok(pageList);
    }

    /**
     * 查询所有已拣货信息
     * @param taskId 出库任务id
     * @return
     */
    @ApiOperation(value = "查询所有已拣货信息", notes = "查询所有已拣货信息")
    @GetMapping(value = "/listAllPicked")
    public Result<IPage<OutboundTaskPickVO>> listAllPicked(@RequestParam(value = "taskId") String taskId,
                                                            @RequestParam(value = "materialName",required = false) String materialName,
                                                            @RequestParam(value = "batchCode",required = false) String batchCode,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        IPage<WmsOutReceiptTaskPick> page = new Page<>(pageNo, pageSize);
        IPage<OutboundTaskPickVO> pageList=wmsOutReceiptTaskPickService.listAllPicked(page,taskId,materialName,batchCode);
        return Result.OK(pageList);
    }

    /**
     * 查询所有已拣货信息(全)
     * @param taskId
     * @return
     */
    @ApiOperation(value = "查询所有已拣货信息(全)", notes = "查询所有已拣货信息(全)")
    @GetMapping(value = "/listAllFullPicked")
    public Result<List<OutboundTaskFullPickVO>> listAllFullPicked(@RequestParam(value = "taskId") String taskId,
                                                                  @RequestParam(name = "unCompleted", required = false) Boolean unCompleted,
                                                                  @RequestParam(name = "pdaFilterFlag", required = false) Boolean pdaFilterFlag
                                                                  ) {
        List<OutboundTaskFullPickVO> list=wmsOutReceiptTaskPickService.listAllFullPicked(taskId,unCompleted,pdaFilterFlag);
        return Result.OK(list);
    }

    /**
     * 查询所有已拣货信息(全)-pda用
     * @return
     */
    @ApiOperation(value = "查询所有已拣货信息(全)-pda用", notes = "查询所有已拣货信息(全)-pda用")
    @PostMapping(value = "/pda/listAllFullPicked")
    public Result<List<OutboundTaskFullPickVO>> pdaListAllFullPicked(@RequestBody PdaPickReqVO pdaPickReqVO) {
        List<OutboundTaskFullPickVO> list=wmsOutReceiptTaskPickService.pdaListAllFullPicked(pdaPickReqVO);
        return Result.OK(list);
    }



    /**
     * 分页查询所有已拣货信息(全)
     * @param taskId
     * @return
     */
    @ApiOperation(value = "分页查询所有已拣货信息(全)", notes = "分页查询所有已拣货信息(全)")
    @GetMapping(value = "/listPageAllFullPicked")
    public Result<IPage<OutboundTaskFullPickVO>> listPageAllFullPicked(@RequestParam(value = "taskId") String taskId,
                                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        IPage<WmsOutReceiptTaskPick> page = new Page<>(pageNo, pageSize);
        IPage<OutboundTaskFullPickVO> pageList=wmsOutReceiptTaskPickService.listPageAllFullPicked(page,taskId);
        return Result.OK(pageList);
    }



    /**
     * 增加拣货信息
     * @param addPickVO
     * @return
     */
    @ApiOperation(value = "增加拣货信息", notes = "增加拣货信息")
    @PostMapping(value = "/addPickInfo")
    public Result<Void> addPickInfo(@Valid @RequestBody OutboundTaskAddPickVO addPickVO){
        wmsOutReceiptTaskPickService.addPickInfo(addPickVO);
        return Result.ok();
    }

    /**
     * 取消拣货
     * @param cancelPickVO
     * @return
     */
    @ApiOperation(value = "取消拣货", notes = "取消拣货")
    @PostMapping("cancelPick")
    public Result<Void> cancelPick(@Valid @RequestBody OutboundTaskCancelPickVO cancelPickVO){
        wmsOutReceiptTaskPickService.cancelPick(cancelPickVO);
        return Result.ok();
    }

    /**
     * 根据任务物料id取消拣货
     * @return
     */
    @ApiOperation(value = "根据任务物料id取消拣货", notes = "根据任务物料id取消拣货")
    @PostMapping("cancelPickByTaskMaterialId")
    public Result<Void> cancelPickByTaskMaterialId(@Valid @RequestBody OutboundTaskCancelPickByIdVO cancelPickVO){
        wmsOutReceiptTaskPickService.cancelPickByTaskMaterialId(cancelPickVO);
        return Result.ok();
    }

    /**
     * 获取拣货编号
     * @param taskId
     * @return
     */
    @ApiOperation(value = "获取领料编码", notes = "获取领料编码")
    @GetMapping(value = "/getPickCode")
    public Result<String> getPickCode(@RequestParam(value = "taskId",required = false) String taskId){
        String pickCode=wmsOutReceiptTaskPickService.getPickCode(taskId);
        return Result.ok(pickCode);
    }

    /**
     * 获取出库任务的配置
     * @param taskId
     * @return
     */
    @ApiOperation(value = "获取出库任务的配置", notes = "获取出库任务的配置")
    @GetMapping(value = "/getTaskConfig")
    public Result<JSONObject> getTaskConfig(@RequestParam(value = "taskId",required = false) String taskId){
        JSONObject jsonObject =wmsOutReceiptTaskPickService.getTaskConfig(taskId);
        return Result.ok(jsonObject);
    }


    /**
     * pda扫码确认已拣货物料
     */
    @ApiOperation(value = "pda扫码确认已拣货物料", notes = "pda扫码确认已拣货物料")
    @GetMapping("/pda/getMaterialByNameAndTaskId")
    public Result<List<OutboundTaskFullPickVO>> getMaterialByNameAndTaskId(@ApiParam("批次号或物料编码") String name, @ApiParam("出库任务id") String outReceiptTaskId) {
        List<OutboundTaskFullPickVO> list=wmsOutReceiptTaskPickService.getMaterialByNameAndTaskId(name,outReceiptTaskId);
        return Result.ok(list);
    }

    /**
     * pda扫码确认未拣货物料
     */
    @ApiOperation(value = "pda扫码确认未拣货物料", notes = "pda扫码确认未拣货物料")
    @GetMapping("/pda/getUnPickMaterialByNameAndTaskId")
    public Result<List<OutboundTaskUnPickVO>> getUnPickMaterialByNameAndTaskId(@ApiParam("批次号或物料编码") String name, @ApiParam("出库任务id") String outReceiptTaskId) {
        List<OutboundTaskUnPickVO> list=wmsOutReceiptTaskPickService.getUnPickMaterialByNameAndTaskId(name,outReceiptTaskId);
        return Result.ok(list);
    }


}
